package cz.cvut.sefcijak.zatacka;

//import pt.webprods.android.file.manager.R;
import android.app.Activity;
import android.os.Bundle;

import android.util.Log;
import android.widget.*;
import android.net.*;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;

/**
 * Created with IntelliJ IDEA.
 * User: buddha
 * Date: 5.5.13
 * Time: 13:47
 * To change this template use File | Settings | File Templates.
 */
public class NetGameActivity extends GameActivity {
    private static final String TAG = "DEBug";
    public static String IpAddress;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(this);
        IpAddress = getLocalIpAddress();
        /*
        RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
        int checkedRadioButton = radioGroup.getCheckedRadioButtonId();
        switch (checkedRadioButton) {
            case R.id.radioServer:
                new NetGameServer().start();
                break;
            case R.id.radioClient:
                new NetGameClient().start();
                break;
        }
        */
    }
    public String getLocalIpAddress() {
        String ip = " ";
        try {
            for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
                NetworkInterface intf = en.nextElement();
                for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress()) {
                        Log.e(TAG, inetAddress.getHostAddress().toString());
                        ip = inetAddress.getHostAddress().toString();
                    }
                }
            }
        } catch (Exception ex) {
            Log.e(TAG, ex.toString());
        }
        return ip;
    }

}



/*

    //getLocalIpAddress();

    public void getLocalIpAddress() {
        try {
            for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
                NetworkInterface intf = en.nextElement();
                for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress()) {
                        Log.e(TAG, inetAddress.getHostAddress().toString());
                    }
                }
            }
        } catch (SocketException ex) {
            Log.e(TAG, ex.toString());
        }
    }
}
       */